package com.bhs.sansong.ui.order;

import static com.bhs.sansong.base.Constants.serviceTel;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Intent;
import android.graphics.Typeface;
import android.location.Location;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.RotateAnimation;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView;

import com.amap.api.maps.MapView;
import com.bhs.sansong.R;
import com.bhs.sansong.adapter.HavePaidAdapter;
import com.bhs.sansong.adapter.PictureShowAdapter;
import com.bhs.sansong.adapter.UnpaidAdapter;
import com.bhs.sansong.base.BaseActivity;
import com.bhs.sansong.base.BaseBean;
import com.bhs.sansong.bean.FeeDetail;
import com.bhs.sansong.bean.MenuBean;
import com.bhs.sansong.bean.OperationEvent;
import com.bhs.sansong.bean.OrderDetailsBean;
import com.bhs.sansong.bean.PictureShowBean;
import com.bhs.sansong.net.Config;
import com.bhs.sansong.net.NetCallBack;
import com.bhs.sansong.ui.dialog.BottomSelectListDialog;
import com.bhs.sansong.ui.dialog.BottomSelectPhone2Dialog;
import com.bhs.sansong.ui.dialog.LogisticsTrackDialog;
import com.bhs.sansong.ui.dialog.MyClickListener;
import com.bhs.sansong.ui.dialog.MyClickListener2;
import com.bhs.sansong.ui.orderDispose.ComplaintActivity;
import com.bhs.sansong.ui.other.WebViewActivity;
import com.bhs.sansong.ui.shipments.IssueNewOrderActivity;
import com.bhs.sansong.utils.CountDownTimerUtils;
import com.bhs.sansong.utils.DateUtils;
import com.bhs.sansong.utils.GetDistanceUtils;
import com.bhs.sansong.utils.MapUtil;
import com.bhs.sansong.utils.MyUtils;
import com.bhs.sansong.utils.StatusBarUtil;
import com.bhs.sansong.utils.ToastUtil;
import com.bhs.sansong.view.ExpandView;
import com.bhs.sansong.view.IInterceptChecker;
import com.bhs.sansong.view.SlideContentLayout;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestOptions;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.google.android.material.imageview.ShapeableImageView;
import com.google.gson.Gson;
import com.lxj.xpopup.XPopup;
import com.lxj.xpopup.core.BasePopupView;
import com.lxj.xpopup.interfaces.OnConfirmListener;
import com.lxj.xpopup.util.SmartGlideImageLoader;

import org.greenrobot.eventbus.EventBus;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

import okhttp3.ResponseBody;
import retrofit2.Response;

/**
 * 订单详情
 */
public class OrderDetailsActivity extends BaseActivity implements View.OnClickListener, NetCallBack, IInterceptChecker {

    private MapView mMapView;
    private View mView2;
    private FrameLayout mFlTitle;
    private RelativeLayout mRlTitle;
    private FrameLayout mFlBack;
    private FrameLayout mFlShare;
    private SlideContentLayout mSlideLayout;
    private ScrollView mSvInfo;
    private LinearLayout mLlLogisticsTrack;
    private TextView mTvHint;
    private LinearLayout mLlCostInformation;
    private TextView mTvCostBreakdown2;
    private TextView mTvUnpaid;
    private RecyclerView mRvUnpaid;
    private LinearLayout mLlHavePaid;
    private TextView mTvPaidExpenses2;
    private RecyclerView mRvHavePaid;
    private LinearLayout mLlPersonnelInformation;
    private ShapeableImageView mIvHeadPortrait;
    private TextView mTvTailNumber;
    private TextView mTvPhoneNumber;

    private ImageView mIvSendMessage;
    private ImageView mIvCall;
    private LinearLayout mOrderInformation;
    private TextView mTvTime;
    private TextView mTvDistance;
    private ConstraintLayout mClLocation;
    private TextView mTvPlaceDeparture;
    private View mView;
    private TextView mTvDestination;
    private TextView mTvDepartureAddress;
    private TextView mTvDeliveryAddress;
    private TextView mTvDepartureCompany;
    private TextView mTvDeliveryCompany;
    private TextView mTvDepartureInfo;
    private TextView mTvDeliveryInfo;
    private TextView mTvOrderNumber;
    private TextView mTvCopy;
    private ExpandView mEvOrderInfo;
    private TextView mTvOrderTime;
    private LinearLayout mLlAppointment;
    private TextView mTvAppointmentTime;
    private TextView mTvOrderType;
    private TextView mTvIsInvoice;
    private TextView mTvLogisticsType;
    private TextView mTvRecoveryStrip;
    private TextView mTvRemakeLabel;
    private TextView mTvRemake;
    private LinearLayout mLlOrderInfo;
    private TextView mTvStatus;
    private ImageView mIvStatus;
    private LinearLayout mLlGoodsInfo2;
    private RecyclerView mRvPicture;
    private TextView mTvQuantity;
    private TextView mTvWeight;
    private TextView mTvVolume;
    private TextView mTvDescriptionGoods;
    private ExpandView mEvCargoInformation;
    private TextView mTvPackagingType;
    private TextView mTvDeliveryType;
    private TextView mTvDistributionType;
    private RelativeLayout mLlSite;
    private TextView mTvOneselfLabel;
    private TextView mTvPickUpCargoByOneself;
    private TextView mTvIsomerism;
    private TextView mTvHeteroideusVolume;
    private TextView mTvDeclaredValue;
    private LinearLayout mLlGoodsInfo;
    private TextView mTvStatus2;
    private ImageView mIvStatus2;
    private LinearLayout mCargoInformation;
    private TextView mTvCostBreakdown;
    private TextView mTvPaidExpenses;
    private RecyclerView mRvHavePaid2;
    private TextView mTvService;
    private TextView mTvAgreement;
    private RelativeLayout mRlOperation;
    private TextView mTvMore;
    private LinearLayout mLlTransportDocument;
    private TextView tvPaymentMethod;

    private String deliver_sn;
    private RotateAnimation animation;
    private RotateAnimation animation2;
    private PictureShowAdapter pictureShowAdapter;
    private Button btnCancelOrder;
    private TextView tvScore;
    private TextView tvCountDown;
    private RelativeLayout rlWaitOrder;
    private TextView tvAssistant;
    private TextView tvLogisticsTrack;
    private OrderDetailsBean.DataDTO data;
    private Button mBtnOneMore;
    private Button mBtnRelaunch;
    private Button mBtnConfirmReceipt;
    private TextView mTvNavigation;
    private TextView mTvMoreOrder;
    private TextView mTvComplaint;
    private TextView mTvTimeRemaining;
    private Button mBtnElectronicFaceSheet;
    private ClipData mClipData;   //剪切板Data对象
    private ClipboardManager mClipboardManager;   //剪切板管理工具类
    private ExpandView expandView, evCargoInformation;
    private TextView tvStatus, tvStatus2;
    private ImageView ivStatus, ivStatus2;

    @Override
    public int initLayout() {
        return R.layout.activity_order_details;
    }

    @SuppressLint("ClickableViewAccessibility")
    @Override
    public void initData() {
        // 1. 注册mClipboardManager
        mClipboardManager = (ClipboardManager)getSystemService(CLIPBOARD_SERVICE);
        pictureShowAdapter = new PictureShowAdapter(R.layout.item_picture3);
        mRvPicture.setAdapter(pictureShowAdapter);
        mRvPicture.setLayoutManager(new GridLayoutManager(mActivity, 3));
        mSlideLayout.setInterceptChecker(this);
        mFlTitle.post(new Runnable() {
            @Override
            public void run() {
                int viewHeight = mFlTitle.getHeight();
                int Height = mView2.getHeight();
                int layoutHeight = MyUtils.getScreenHeight(mContext) / 2 - viewHeight - Height;
                //mSlideLayout.setY(layoutHeight);
                mSlideLayout.setHeight(layoutHeight - 20);
                mMapView.setLayoutParams(new RelativeLayout.LayoutParams(MyUtils.getScreenWidth(mContext), MyUtils.getScreenHeight(mContext) / 2));
            }
        });
        mSvInfo.setOnScrollChangeListener(new View.OnScrollChangeListener() {
            @Override
            public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
                if (mSvInfo.getScrollY() == 0) {
                    //顶部
                    shouldIntercept = true;
                } else {
                    shouldIntercept = false;
                }

            }
        });
        mSlideLayout.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View view, MotionEvent motionEvent) {
                float alpha = (1000 - mSlideLayout.getY()) / 1000;
                mRlTitle.setAlpha(alpha);
                mView2.setAlpha(alpha);
                return false;
            }
        });

    }


    @SuppressLint("NonConstantResourceId")
    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_cancel_order:
                startActivity(new Intent(mActivity, CancelOrderActivity.class).putExtra("deliver_sn", deliver_sn));
                break;
            case R.id.tv_cost_breakdown:
            case R.id.tv_cost_breakdown2:
                startActivity(new Intent(mActivity, ObviousCostActivity.class)
                        .putParcelableArrayListExtra("FeeDetail", data.getFee_detail())
                        .putExtra("orderType", data.getOrder_info().getOrder_type()));
                break;
            case R.id.btn_one_more:
            case R.id.tv_more_order:
                startActivity(new Intent(mActivity, IssueNewOrderActivity.class)
                        .putExtra("deliver_sn", deliver_sn));
                break;
            case R.id.btn_relaunch:
                new XPopup.Builder(mActivity)
                        .asConfirm("提示", "确认再次发起吗？",
                                "取消", "确定",
                                new OnConfirmListener() {
                                    @Override
                                    public void onConfirm() {
                                        networkRequest(netApi.reapply_order(deliver_sn),
                                                OrderDetailsActivity.this, 101);
                                    }
                                }, null, false)
                        .show();

                break;
            case R.id.btn_confirm_receipt:
                new XPopup.Builder(mActivity)
                        .asConfirm("提示", "确认收货吗？",
                                "取消", "确定",
                                new OnConfirmListener() {
                                    @Override
                                    public void onConfirm() {
                                        //确认收货
                                        networkRequest(netApi.confirm_receipt(deliver_sn),
                                                OrderDetailsActivity.this, 101);
                                    }
                                }, null, false)
                        .show();
                break;
            case R.id.tv_navigation:
                bottomSelect();
                break;
            case R.id.tv_complaint:
                startActivity(new Intent(mActivity, ComplaintActivity.class).putExtra("deliver_sn", deliver_sn));
                break;
            case R.id.ll_transport_document:
                startActivity(new Intent(mActivity, TransportDocumentActivity.class).putExtra("deliver_sn", deliver_sn));
                break;
            case R.id.btn_electronic_face_sheet:
                String url = Config.agreementUrl + "index?type=android&deliver_sn=" + deliver_sn;
                startActivity(new Intent(mActivity, WebViewActivity.class)
                        .putExtra("url", url)
                        .putExtra("title", "电子面单"));
                break;
            case R.id.ll_Logistics_track:
                logisticsTrack();
                break;
            case R.id.iv_call:
                contactImmediately();
                break;
            case R.id.tv_copy:
                //创建一个新的文本clip对象
                mClipData = ClipData.newPlainText("Simple text", deliver_sn);
                //把clip对象放在剪贴板中
                mClipboardManager.setPrimaryClip(mClipData);
                ToastUtil.show("复制成功");
                break;
            case R.id.tv_agreement:
                mActivity.startActivity(new Intent(mActivity, WebViewActivity.class)
                        .putExtra("url", Config.getTransportationUrl())
                        .putExtra("title", "运输协议"));
                break;
            case R.id.tv_service:
                MyUtils.callPhone(mActivity, serviceTel);
                //startActivity(new Intent(mActivity, CustomerServiceActivity.class));
                break;
            case R.id.ll_order_info:
                shrink();
                break;
            case R.id.ll_goods_info:
                shrink2();
                break;
        }
    }

    private void shrink2() {
        evCargoInformation.expand();
        if (evCargoInformation.isShow) {
            tvStatus2.setText("收起");
            ivStatus2.startAnimation(animation2);//开始动画
        } else {
            tvStatus2.setText("展开");
            ivStatus2.startAnimation(animation);//开始动画
        }
    }

    private void shrink() {
        //创建旋转动画
        expandView.expand();
        if (expandView.isShow) {
            tvStatus.setText("收起");
            ivStatus.startAnimation(animation2);//开始动画
        } else {
            ivStatus.startAnimation(animation);//开始动画
            tvStatus.setText("展开");
        }
    }

    BottomSelectPhone2Dialog bottomSelectDialog;
    BasePopupView basePopupView;

    private void contactImmediately() {
        if (basePopupView == null) {
            OrderDetailsBean.DataDTO.LogisticsCompanyInfoDTO companyInfo = data.getLogistics_company_info();
            bottomSelectDialog = new BottomSelectPhone2Dialog(mActivity,
                    companyInfo.getMobile(), companyInfo.getFixed_telephone(), "");
            basePopupView = new XPopup.Builder(mActivity)
                    .asCustom(bottomSelectDialog)
                    .show();
        } else {
            basePopupView.show();
        }
    }

    private LogisticsTrackDialog trackDialog;

    private void logisticsTrack() {
        if (trackDialog == null) {
            trackDialog = new LogisticsTrackDialog(mActivity, deliver_sn);
            trackDialog.setMyClickListener(new MyClickListener() {
                @Override
                public void onClick(View v) {
                    //创建一个新的文本clip对象
                    mClipData = ClipData.newPlainText("Simple text", deliver_sn);
                    //把clip对象放在剪贴板中
                    mClipboardManager.setPrimaryClip(mClipData);
                    ToastUtil.show("复制成功");
                }
            });
        }
        trackDialog.show();
    }

    private BottomSelectListDialog listDialog;

    private void bottomSelect() {
        if (listDialog == null) {
            List<MenuBean> list = new ArrayList<>();
            list.add(new MenuBean("百度地图"));
            list.add(new MenuBean("高德地图"));
            list.add(new MenuBean("取消"));
            listDialog = new BottomSelectListDialog(mActivity, list);
            listDialog.setMyClickListener(new MyClickListener2() {
                @Override
                public void onClick(String id, String info) {
                    if (id.equals("百度地图")) {
                        openBaiDuMap();
                    } else if (id.equals("高德地图")) {
                        openGaoDeMap();
                    }
                }
            });
        }
        listDialog.show();
    }

    private void openBaiDuMap() {
        if (MapUtil.isBaiduMapInstalled()) {
            MapUtil.openBaiDuNavi(mActivity, 0, 0, null,
                    Double.parseDouble(data.getLogistics_company_info().getLatitude()), Double.parseDouble(data.getLogistics_company_info().getLongitude()),
                    data.getLogistics_company_info().getAddress());
        } else {
            //这里必须要写逻辑，不然如果手机没安装该应用，程序会闪退，这里可以实现下载安装该地图应用
            ToastUtil.show("尚未安装百度地图");
        }
    }

    private void openGaoDeMap() {
        if (MapUtil.isGdMapInstalled()) {
            MapUtil.openGaoDeNavi(mActivity, 0, 0, null,
                    Double.parseDouble(data.getLogistics_company_info().getLatitude()), Double.parseDouble(data.getLogistics_company_info().getLongitude()),
                    data.getLogistics_company_info().getAddress());
        } else {
            //这里必须要写逻辑，不然如果手机没安装该应用，程序会闪退，这里可以实现下载安装该地图应用
            ToastUtil.show("尚未安装高德地图");
        }
    }

    @Override
    public void onResponse(int requestCode, String json, Response<ResponseBody> response) throws Exception {
        if (requestCode == 0) {
            loadingPopupDismiss();
            OrderDetailsBean detailsBean = new Gson().fromJson(json, OrderDetailsBean.class);
            if (detailsBean.isStatus()) {
                data = detailsBean.getData();
                setData(data);
            }
        } else {
            BaseBean bean = new Gson().fromJson(json, BaseBean.class);
            if (bean.isStatus()) {
                loadingPopupShow();
                networkRequest(netApi.getOrderDetails(deliver_sn), this);
            } else {
                ToastUtil.show(bean.getMsg());
            }
        }
    }

    private void setData(OrderDetailsBean.DataDTO data) {
        if (data.getOrder_info().getStatus() == 3) {
            CountDownTimerUtils mCountDownTimerUtils = new CountDownTimerUtils(tvCountDown, data.getOrder_info().getTimeout_time() * 1000L - System.currentTimeMillis());
            mCountDownTimerUtils.start();
            mCountDownTimerUtils.setMyClickListener(new MyClickListener() {
                @Override
                public void onClick(View v) {
                    networkRequest(netApi.getOrderDetails(deliver_sn), OrderDetailsActivity.this);
                }
            });
        }
        if (data.getOrder_info().getStatus() > 3 && data.getOrder_info().getStatus() < 20) {
            mTvComplaint.setVisibility(View.VISIBLE);
        }
        btnCancelOrder.setVisibility(data.getOrder_info().getStatus() < 11  ? View.VISIBLE : View.GONE);
        mTvTimeRemaining.setText(String.format("订单剩余确认时间：%s",DateUtils.getDaytime(data.getOrder_info().getConfirm_time())));
        mTvTimeRemaining.setVisibility(data.getOrder_info().getStatus() == 15  ? View.VISIBLE : View.GONE);
        mLlTransportDocument.setVisibility(data.getOrder_info().getStatus() == 15 || data.getOrder_info().getStatus() == 20 ? View.VISIBLE : View.GONE);
        rlWaitOrder.setVisibility(data.getOrder_info().getStatus() == 3 ? View.VISIBLE : View.GONE);
        mLlLogisticsTrack.setVisibility(data.getOrder_info().getStatus() == 3 ? View.GONE : View.VISIBLE);
        mLlPersonnelInformation.setVisibility(data.getLogistics_company_info().getCompany_name() == null ? View.GONE : View.VISIBLE);
        mTvHint.setText(MyUtils.setHint(data));
        MyUtils.setAssistant(tvAssistant, tvLogisticsTrack, data);
        mTvAppointmentTime.setText(DateUtils.stampToDate(data.getOrder_info().getYuyue_time()));
        mBtnRelaunch.setVisibility(data.getOrder_info().getStatus() == 90 ? View.VISIBLE : View.GONE);
        mBtnConfirmReceipt.setVisibility(data.getOrder_info().getStatus() == 15 ? View.VISIBLE : View.GONE);
        List<FeeDetail> list = new ArrayList<>();
        List<FeeDetail> havePaidList = new ArrayList<>();
        BigDecimal bdHavePaid = new BigDecimal("0");//已支付总费用
        BigDecimal unPaid = new BigDecimal("0");//未支付总费用
        BigDecimal weChatPay = new BigDecimal("0");//微信支付
        BigDecimal offlineTransaction = new BigDecimal("0");//线下支付
        BigDecimal balancePay = new BigDecimal("0");//余额支付
        BigDecimal payAlipay = new BigDecimal("0");//支付宝支付
        for (FeeDetail datum : data.getFee_detail()) {
            if (datum.getStatus() == 2) {
                //已支付
                bdHavePaid = bdHavePaid.add(new BigDecimal(datum.getMoney()));
            }
            if (datum.getStatus() == 0) {
                unPaid = unPaid.add(new BigDecimal(datum.getMoney()));
                //未支付
                list.add(datum);
            }
            if (datum.getPay_type() == 4) {
                weChatPay = weChatPay.add(new BigDecimal(datum.getMoney()));
            }
            if (datum.getPay_type() == 3) {
                payAlipay = payAlipay.add(new BigDecimal(datum.getMoney()));
            }
            if (datum.getPay_type() == 2) {
                balancePay = balancePay.add(new BigDecimal(datum.getMoney()));
            }
            if (datum.getPay_type() == 1) {
                offlineTransaction = offlineTransaction.add(new BigDecimal(datum.getMoney()));
            }
        }

        if (!offlineTransaction.toString().equals("0")) {
            havePaidList.add(new FeeDetail("线下支付", offlineTransaction.toString()));
        }
        if (!balancePay.toString().equals("0")) {
            havePaidList.add(new FeeDetail("余额支付", balancePay.toString()));
        }
        if (!payAlipay.toString().equals("0")) {
            havePaidList.add(new FeeDetail("支付宝支付", payAlipay.toString()));
        }
        if (!weChatPay.toString().equals("0")) {
            havePaidList.add(new FeeDetail("微信支付", weChatPay.toString()));
        }
        HavePaidAdapter havePaidAdapter = new HavePaidAdapter(havePaidList);
        //有两个费用明细 老板说未支付的在上门 支付完在下面
        //总支付金额
        mTvPaidExpenses.setText(String.format("%s元", bdHavePaid));
        mTvPaidExpenses2.setText(String.format("%s元", bdHavePaid));
        //未支付总金额
        mTvUnpaid.setText(String.format("%s元", unPaid));

        if (bdHavePaid.toString().equals("0")) {
            mActivity.findViewById(R.id.ll_have_paid).setVisibility(View.GONE);
        }
        if (data.getOrder_info().getPay_status() == 0) {
            //有未支付的费用
            mLlCostInformation.setVisibility(View.VISIBLE);
            mCargoInformation.setVisibility(View.GONE);
            mRvUnpaid.setLayoutManager(new LinearLayoutManager(mActivity));
            mRvUnpaid.setAdapter(new UnpaidAdapter(list, data.getOrder_info().getPay_method()));
            mRvHavePaid.setAdapter(havePaidAdapter);
            mRvHavePaid.setLayoutManager(new LinearLayoutManager(mActivity));
        } else if (data.getOrder_info().getPay_status() == 2) {
            //已支付
            mLlCostInformation.setVisibility(View.GONE);
            mCargoInformation.setVisibility(View.VISIBLE);
            mRvHavePaid2.setAdapter(havePaidAdapter);
            mRvHavePaid2.setLayoutManager(new LinearLayoutManager(mActivity));
        }

        if (MyUtils.isEmpty(data.getFee_detail())) {
            mLlCostInformation.setVisibility(View.GONE);
            mCargoInformation.setVisibility(View.GONE);
        }
        animation = new RotateAnimation(0, 180, mIvStatus.getWidth() / 2, mIvStatus.getHeight() / 2);
        animation.setDuration(500);
        animation.setFillAfter(true);//设置为true，动画转化结束后被应用

        animation2 = new RotateAnimation(180, 0, mIvStatus.getWidth() / 2, mIvStatus.getHeight() / 2);
        animation2.setDuration(500);
        animation2.setFillAfter(true);//设置为true，动画转化结束后被应用
        OrderDetailsBean.DataDTO.OrderInfoDTO orderInfo = data.getOrder_info();
        //还没公司接单
        if (!TextUtils.isEmpty(data.getLogistics_company_info().getCompany_name())) {
            double score = Double.parseDouble(data.getLogistics_company_info().getGrade_score()) /(data.getLogistics_company_info().getComment_num() + 1) ;
            tvScore.setText(String.format("评分：%s", MyUtils.format2(score)));
            mTvTailNumber.setText( data.getLogistics_company_info().getCompany_name());
            mTvPhoneNumber.setText(String.format("地址：%s", data.getLogistics_company_info().getAddress()));
            RequestOptions options = new RequestOptions()
                    .placeholder(R.mipmap.ic_cow)//图片加载出来前，显示的图片
                    .fallback(R.mipmap.ic_cow) //url为空的时候,显示的图片
                    .error(R.mipmap.ic_cow);//图片加载失败后，显示的图片
            Glide.with(mActivity).load(data.getLogistics_company_info().getCompany_pic()).apply(options).into(mIvHeadPortrait);
        }
        if (TextUtils.isEmpty(orderInfo.getPickup_province())) {
            mTvDepartureAddress.setText(String.format("%s-%s", orderInfo.getPickup_city(), orderInfo.getPickup_address()));
        } else {
            mTvDepartureAddress.setText(String.format("%s-%s-%s", orderInfo.getPickup_province(), orderInfo.getPickup_city(), orderInfo.getPickup_address()));
        }

        if (TextUtils.isEmpty(orderInfo.getReceive_province())) {
            mTvDeliveryAddress.setText(String.format("%s-%s", orderInfo.getReceive_city(), orderInfo.getReceive_address()));
        } else {
            mTvDeliveryAddress.setText(String.format("%s-%s-%s", orderInfo.getReceive_city(), orderInfo.getReceive_city(), orderInfo.getReceive_address()));
        }

        //出发公司
        MyUtils.setText(mTvDepartureCompany, orderInfo.getPickup_remark());
        //到达公司
        MyUtils.setText(mTvDeliveryCompany, orderInfo.getReceive_remark());

        tvPaymentMethod.setText(orderInfo.getPay_method() == 1 ? "现付" : "到付");
        mTvDepartureInfo.setText(String.format("%s %s", orderInfo.getPickup_truename(), MyUtils.phoneHide(orderInfo.getPickup_mobile())));
        mTvDeliveryInfo.setText(String.format("%s %s", orderInfo.getReceive_truename(), MyUtils.phoneHide(orderInfo.getReceive_mobile())));
        mTvOrderNumber.setText(orderInfo.getDeliver_sn());
        mTvOrderTime.setText(DateUtils.stampToDate(orderInfo.getCreate_time()));
        mTvOrderType.setText(MyUtils.getOrderType(orderInfo.getOrder_type()));
        mTvIsInvoice.setText(MyUtils.isInvoice(orderInfo.getIs_invoice()));
        mTvLogisticsType.setText(MyUtils.getHaulageTime(orderInfo.getDeliver_type(), orderInfo.getTransport_day_max(), orderInfo.getTransport_day_min()));
        mTvRecoveryStrip.setText(MyUtils.getReceiptType(orderInfo.getReceipt_type()));
        MyUtils.setText(mTvRemake, orderInfo.getRemark());
        mTvQuantity.setText(String.valueOf(orderInfo.getGoods_number()));
        mTvWeight.setText(orderInfo.getGoods_weight());
        mTvVolume.setText(orderInfo.getGoods_volume());
        mTvDescriptionGoods.setText(orderInfo.getGoods_name());
        mTvPackagingType.setText(orderInfo.getPack_name());
        mTvDeliveryType.setText(MyUtils.getDeliveryType(orderInfo.getJiaohuo_type()));
        mTvDistributionType.setText(MyUtils.getDistributionType(orderInfo.getPeisong_type()));
        mTvIsomerism.setText(orderInfo.getPack_is_special().equals("1") ? "是" : "否");//是否有异性件
        if (orderInfo.getPack_is_special().equals("1")) {
            mTvHeteroideusVolume.setVisibility(View.VISIBLE);
            mTvHeteroideusVolume.setText(String.format("长x宽x高：%sx%sx%sm", orderInfo.getPack_long(), orderInfo.getPack_width(), orderInfo.getPack_height()));
        }
        StringBuilder stringBuilder = new StringBuilder();
        if (!TextUtils.isEmpty(orderInfo.getOutlets_name())) {
            stringBuilder.append(String.format("公司名称：%s\n", orderInfo.getOutlets_name()));
        }
        if (!TextUtils.isEmpty(orderInfo.getOutlets_address())) {
            stringBuilder.append(String.format("地址：%s\n", orderInfo.getOutlets_address()));
        }
        if (!TextUtils.isEmpty(orderInfo.getOutlets_county())) {
            stringBuilder.append(String.format("负责人：%s\n", orderInfo.getOutlets_contact()));
        }
        if (!TextUtils.isEmpty(orderInfo.getOutlets_mobile())) {
            stringBuilder.append(String.format("电话：%s\n", orderInfo.getOutlets_mobile()));
        }
        if (TextUtils.isEmpty(stringBuilder.toString())) {
            mLlSite.setVisibility(View.GONE);
        } else {
            mTvPickUpCargoByOneself.setText(stringBuilder.toString());//自提网点
        }
        mTvDeclaredValue.setText(orderInfo.getGoods_value_price());
        if (data.getOrder_info().getIs_yuyue() > 0) {
            mLlAppointment.setVisibility(View.VISIBLE);
        } else {
            mLlAppointment.setVisibility(View.GONE);
        }

        if (!MyUtils.isEmpty(data.getImage_list().getImg_0())) {
            List<PictureShowBean> pictureShowBeanList = new ArrayList<>();
            List<Object> urls = new ArrayList<>();
            for (OrderDetailsBean.DataDTO.ImageListDTO.ImgDTO imgDTO : data.getImage_list().getImg_0()) {
                pictureShowBeanList.add(new PictureShowBean(imgDTO.getImg_path()));
                urls.add(MyUtils.watermark(imgDTO.getImg_path()));
            }
            pictureShowAdapter.setNewData(pictureShowBeanList);
            pictureShowAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
                @Override
                public void onItemClick(BaseQuickAdapter adapter, View view, int position) {
                    new XPopup.Builder(mActivity)
                            .asImageViewer(view.findViewById(R.id.iv_picture), position, urls, null, new SmartGlideImageLoader())
                            .isShowSaveButton(false)
                            .show();
                }
            });
        }

    }

    @Override
    public void onFailure(int requestCode) {

    }

    @Override
    public void initView(@Nullable Bundle savedInstanceState) {
        super.initView(savedInstanceState);
        mMapView.onCreate(savedInstanceState);
        mBtnOneMore = findViewById(R.id.btn_one_more);
        mBtnRelaunch = findViewById(R.id.btn_relaunch);
        mBtnConfirmReceipt = findViewById(R.id.btn_confirm_receipt);
        mBtnOneMore.setOnClickListener(this);
        mBtnRelaunch.setOnClickListener(this);
        mBtnConfirmReceipt.setOnClickListener(this);
        mBtnElectronicFaceSheet = findViewById(R.id.btn_electronic_face_sheet);
        mBtnElectronicFaceSheet.setOnClickListener(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        //在activity执行onDestroy时执行mMapView.onDestroy()，销毁地图
        mMapView.onDestroy();
    }

    @Override
    protected void onResume() {
        super.onResume();
        //在activity执行onResume时执行mMapView.onResume ()，重新绘制加载地图
        mMapView.onResume();
        loadingPopupShow();
        networkRequest(netApi.getOrderDetails(deliver_sn), this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        //在activity执行onPause时执行mMapView.onPause ()，暂停地图的绘制
        mMapView.onPause();
    }

    @Override
    public void initView() {
        StatusBarUtil.setTranslucentStatus(this, true);
        StatusBarUtil.setStatusBarDarkTheme(this, true);
        deliver_sn = getIntent().getStringExtra("deliver_sn");
        tvScore = findViewById(R.id.tv_score);
        tvCountDown = findViewById(R.id.tv_count_down);
        rlWaitOrder = findViewById(R.id.rl_Wait_order);
        mMapView = findViewById(R.id.map);
        mView2 = findViewById(R.id.view2);
        mFlTitle = findViewById(R.id.fl_title);
        mRlTitle = findViewById(R.id.rl_title);
        mFlBack = findViewById(R.id.fl_back);
        mFlShare = findViewById(R.id.fl_share);
        mSlideLayout = findViewById(R.id.slide_layout);
        mSvInfo = findViewById(R.id.sv_info);
        mLlLogisticsTrack = findViewById(R.id.ll_Logistics_track);
        mTvHint = findViewById(R.id.tv_hint);
        mLlCostInformation = findViewById(R.id.ll_cost_information);
        mTvCostBreakdown2 = findViewById(R.id.tv_cost_breakdown2);
        mTvCostBreakdown2.setOnClickListener(this);
        mTvUnpaid = findViewById(R.id.tv_unpaid);
        mRvUnpaid = findViewById(R.id.rv_unpaid);
        mLlHavePaid = findViewById(R.id.ll_have_paid);
        mTvPaidExpenses2 = findViewById(R.id.tv_paid_expenses2);
        mRvHavePaid = findViewById(R.id.rv_have_paid);
        mLlPersonnelInformation = findViewById(R.id.ll_personnel_information);
        mIvHeadPortrait = findViewById(R.id.iv_head_portrait);
        mTvTailNumber = findViewById(R.id.tv_tail_number);
        mTvPhoneNumber = findViewById(R.id.tv_phone_number);
        mIvSendMessage = findViewById(R.id.iv_send_message);
        mIvCall = findViewById(R.id.iv_call);
        mOrderInformation = findViewById(R.id.order_information);
        mTvTime = findViewById(R.id.tv_time);
        mTvDistance = findViewById(R.id.tv_distance);
        mClLocation = findViewById(R.id.cl_location);
        mTvPlaceDeparture = findViewById(R.id.tv_place_departure);
        mView = findViewById(R.id.view);
        mTvDestination = findViewById(R.id.tv_destination);
        mTvDepartureAddress = findViewById(R.id.tv_departure_address);
        mTvDeliveryAddress = findViewById(R.id.tv_delivery_address);
        mTvDepartureCompany = findViewById(R.id.tv_departure_company);
        mTvDeliveryCompany = findViewById(R.id.tv_delivery_company);
        mTvDepartureInfo = findViewById(R.id.tv_departure_info);
        mTvDeliveryInfo = findViewById(R.id.tv_delivery_info);
        mTvOrderNumber = findViewById(R.id.tv_order_number);
        mTvCopy = findViewById(R.id.tv_copy);
        mEvOrderInfo = findViewById(R.id.ev_order_info);
        mTvOrderTime = findViewById(R.id.tv_order_time);
        mLlAppointment = findViewById(R.id.ll_appointment);
        mTvAppointmentTime = findViewById(R.id.tv_appointment_time);
        mTvOrderType = findViewById(R.id.tv_order_type);
        mTvIsInvoice = findViewById(R.id.tv_is_invoice);
        mTvLogisticsType = findViewById(R.id.tv_logistics_type);
        mTvRecoveryStrip = findViewById(R.id.tv_recovery_strip);
        mTvRemakeLabel = findViewById(R.id.tv_remake_label);
        mTvRemake = findViewById(R.id.tv_remake);
        mLlOrderInfo = findViewById(R.id.ll_order_info);
        mTvStatus = findViewById(R.id.tv_status);
        mIvStatus = findViewById(R.id.iv_status);
        mLlGoodsInfo2 = findViewById(R.id.ll_goods_info2);
        mRvPicture = findViewById(R.id.rv_picture);
        mTvQuantity = findViewById(R.id.tv_quantity);
        mTvWeight = findViewById(R.id.tv_weight);
        mTvVolume = findViewById(R.id.tv_volume);
        mTvDescriptionGoods = findViewById(R.id.tv_description_goods);
        mEvCargoInformation = findViewById(R.id.ev_cargo_information);
        mTvPackagingType = findViewById(R.id.tv_packaging_type);
        mTvDeliveryType = findViewById(R.id.tv_delivery_type);
        mTvDistributionType = findViewById(R.id.tv_distribution_type);
        mLlSite = findViewById(R.id.ll_site);
        mTvOneselfLabel = findViewById(R.id.tv_oneself_label);
        mTvPickUpCargoByOneself = findViewById(R.id.tv_pick_up_cargo_by_oneself);
        mTvIsomerism = findViewById(R.id.tv_isomerism);
        mTvHeteroideusVolume = findViewById(R.id.tv_heteroideus_volume);
        mTvDeclaredValue = findViewById(R.id.tv_declared_value);
        mLlGoodsInfo = findViewById(R.id.ll_goods_info);
        mTvStatus2 = findViewById(R.id.tv_status2);
        mIvStatus2 = findViewById(R.id.iv_status2);
        mCargoInformation = findViewById(R.id.cargo_information);
        mTvCostBreakdown = findViewById(R.id.tv_cost_breakdown);
        mTvCostBreakdown.setOnClickListener(this);
        mTvPaidExpenses = findViewById(R.id.tv_paid_expenses);
        mRvHavePaid2 = findViewById(R.id.rv_have_paid2);
        mTvService = findViewById(R.id.tv_service);
        mTvAgreement = findViewById(R.id.tv_agreement);
        mRlOperation = findViewById(R.id.rl_operation);
        mTvMore = findViewById(R.id.tv_more);
        btnCancelOrder = findViewById(R.id.btn_cancel_order);
        btnCancelOrder.setOnClickListener(this);
        tvAssistant = findViewById(R.id.tv_assistant);
        tvLogisticsTrack = findViewById(R.id.tv_logistics_track);
        mTvNavigation = findViewById(R.id.tv_navigation);
        mTvMoreOrder = findViewById(R.id.tv_more_order);
        mTvComplaint = findViewById(R.id.tv_complaint);
        mTvNavigation.setOnClickListener(this);
        mTvMoreOrder.setOnClickListener(this);
        mTvComplaint.setOnClickListener(this);
        mLlTransportDocument = findViewById(R.id.ll_transport_document);
        mLlTransportDocument.setOnClickListener(this);
        mTvTimeRemaining=findViewById(R.id.tv_time_remaining);
        mLlLogisticsTrack.setOnClickListener(this);
        mIvCall.setOnClickListener(this);
        mTvCopy.setOnClickListener(this);
        mTvAgreement.setOnClickListener(this);
        mTvService.setOnClickListener(this);
        tvPaymentMethod=findViewById(R.id.tv_payment_method);
        mLlOrderInfo.setOnClickListener(this);
        mLlGoodsInfo.setOnClickListener(this);
        expandView = mActivity.findViewById(R.id.ev_order_info);
        evCargoInformation = mActivity.findViewById(R.id.ev_cargo_information);
        ivStatus = mActivity.findViewById(R.id.iv_status);
        ivStatus2 = mActivity.findViewById(R.id.iv_status2);
        tvStatus = mActivity.findViewById(R.id.tv_status);
        tvStatus2 = mActivity.findViewById(R.id.tv_status2);
    }

    boolean shouldIntercept = true;

    @Override
    public boolean checkIfIntercept() {
        return shouldIntercept;
    }
}